package cn.doitedu.spring_boot.dao;

import cn.doitedu.spring_boot.beans.User;
import org.springframework.stereotype.Component;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * @Date 22.3.24
 * @Created by HANGGE
 * @Description
 */
@Component
public class UserDaoImpl implements  UserDao{

    @Override
    public int addUser(User user) throws Exception {
        // 操作数据库 写 完成注册  JDBC  操作数据库
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/doit30", "root", "root");
        PreparedStatement ps = conn.prepareStatement("insert  into  tb_account (uid , account , password) values (null ,?,?)");
        ps.setString(1,user.getAccount());
        ps.setString(2,user.getPassword());
        int i = ps.executeUpdate();
        ps.close();
        conn.close();
        return i;
    }
}
